package com.androidx.p013lv.mine.model;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import com.androidx.p013lv.base.BaseSdk;
import com.androidx.p013lv.base.bean.NoticeBean;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.utils.DownloadFileUtils;
import com.androidx.p013lv.mine.bean.DownLoadBean;
import com.androidx.p013lv.mine.bean.VersionBean;
import com.lzy.okgo.model.Progress;
import com.lzy.okserver.download.DownloadListener;

import java.io.File;
import java.util.Objects;

/* renamed from: com.androidx.lv.mine.model.VersionUpdateModel */
public class VersionUpdateModel extends ViewModel {
    private MutableLiveData<DownLoadBean> downLoadBean;
    private MutableLiveData<BaseRes<NoticeBean>> noticeData;
    private MutableLiveData<BaseRes<VersionBean>> versionDate;

    public MutableLiveData<BaseRes<VersionBean>> getVersionDate() {
        if (this.versionDate == null) {
            this.versionDate = new MutableLiveData<>();
        }
        return this.versionDate;
    }

    public MutableLiveData<DownLoadBean> getDownLoadData() {
        if (this.downLoadBean == null) {
            this.downLoadBean = new MutableLiveData<>();
        }
        return this.downLoadBean;
    }

    public void checkLatestVersion() {
        HttpUtils.getInsatance().get(UrlManager.getInsatance().checkVersionState(), new HttpCallback<BaseRes<VersionBean>>("checkLatestVersion") {
            /* class com.androidx.p013lv.mine.model.VersionUpdateModel.C13671 */

            public void onLvSuccess(BaseRes<VersionBean> baseRes) {
                VersionUpdateModel.this.versionDate.setValue(baseRes);
            }
        });
    }

    public void doDownLoadFile(String str) {
        String[] split = str.split("/");
        DownloadFileUtils.startDownloadFile(str,
                Key.VERSION_TAG,
                Objects.requireNonNull(BaseSdk.getContext().getExternalFilesDir(null)).getAbsolutePath(),
                split[split.length - 1], new DownloadListener(Key.VERSION_TAG) {
            /* class com.androidx.p013lv.mine.model.VersionUpdateModel.C13682 */

            @Override // p000a.lzy.p004a.ProgressListener
            public void onRemove(Progress progress) {
            }

            @Override // p000a.lzy.p004a.ProgressListener
            public void onStart(Progress progress) {
                DownLoadBean downLoadBean = new DownLoadBean();
                downLoadBean.setCode(0);
                downLoadBean.setProgress(progress);
                VersionUpdateModel.this.downLoadBean.setValue(downLoadBean);
            }

            @Override // p000a.lzy.p004a.ProgressListener
            public void onProgress(Progress progress) {
                DownLoadBean downLoadBean = new DownLoadBean();
                downLoadBean.setCode(1);
                downLoadBean.setProgress(progress);
                VersionUpdateModel.this.downLoadBean.setValue(downLoadBean);
            }

            @Override // p000a.lzy.p004a.ProgressListener
            public void onError(Progress progress) {
                DownLoadBean downLoadBean = new DownLoadBean();
                downLoadBean.setCode(2);
                downLoadBean.setProgress(progress);
                VersionUpdateModel.this.downLoadBean.setValue(downLoadBean);
            }

            public void onFinish(File file, Progress progress) {
                DownLoadBean downLoadBean = new DownLoadBean();
                downLoadBean.setCode(3);
                downLoadBean.setProgress(progress);
                downLoadBean.setFile(file);
                VersionUpdateModel.this.downLoadBean.setValue(downLoadBean);
            }
        });
    }

    public MutableLiveData<BaseRes<NoticeBean>> data() {
        if (this.noticeData == null) {
            this.noticeData = new MutableLiveData<>();
        }
        return this.noticeData;
    }

    public void getNoticeData() {
        HttpUtils.getInsatance().get(UrlManager.getInsatance().noticeMessage(), new HttpCallback<BaseRes<NoticeBean>>("notice") {
            /* class com.androidx.p013lv.mine.model.VersionUpdateModel.C13693 */

            public void onLvSuccess(BaseRes<NoticeBean> baseRes) {
                VersionUpdateModel.this.noticeData.setValue(baseRes);
            }
        });
    }
}
